using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(PolygonCollider2D))]
[RequireComponent(typeof(BoxCollider2D))]
[RequireComponent(typeof(Animation))]
public class Gate : MonoBehaviour
{
    private bool isOpen;
    public bool playerHasKey;
    [SerializeField] private ParticleSystem GateParticle;

    private void Awake()
    {
        isOpen = false;
        GetComponent<BoxCollider2D>().isTrigger = true;
    }

    private void StopGateParticle()
    {
        GateParticle.Stop();
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player") && !isOpen && playerHasKey)
        {
            PlayerStateMachine.Instance.SetState(EPlayerState.Idle);
            isOpen = true;
            GetComponent<Animation>().Play();
            GateParticle.Play();
        }
    }

    public void StartInput()
    {
        PlayerStateMachine.Instance.canInput = true;
    }
    
    public void StopInput()
    {
        PlayerStateMachine.Instance.canInput = false;
        PlayerStateMachine.Instance.SetState(EPlayerState.Idle);
        PlayerStateMachine.Instance.playerInputDirction=Vector3.zero;
        
    }
}
